import sys
import pyglet
from engine.service import (
    ServiceManager, ResourceService
)

def image(filename):
    """
    Convenience function to load an image from the ResourceService,
    if configured.
    """
    try:
        return ServiceManager.instance[ResourceService].image(filename)
    except KeyError: # fallback
        sys.stderr.write("ResourceService is not configured, "+
                         "using fallback")
        return pyglet.image.load(filename)